load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "logical_session_id_helpers",
    srcs = [
        "internal_session_pool.cpp",
        "logical_session_id_helpers.cpp",
    ],
    deps = [
        ":logical_session_cache",
        ":logical_session_id",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/auth",
        "//src/mongo/db/auth:authprivilege",
    ],
)

idl_generator(
    name = "logical_session_id_gen",
    src = "logical_session_id.idl",
    deps = [
        "//src/mongo/crypto:sha256_block_gen",
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "logical_session_cache_gen",
    src = "logical_session_cache.idl",
)

idl_generator(
    name = "logical_session_cache_stats_gen",
    src = "logical_session_cache_stats.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

idl_generator(
    name = "sessions_server_parameters_gen",
    src = "sessions_server_parameters.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

mongo_cc_library(
    name = "logical_session_cache",
    srcs = [
        "logical_session_cache.cpp",
        ":logical_session_cache_gen",
        ":logical_session_cache_stats_gen",
    ],
    hdrs = [
        "logical_session_cache.h",
    ],
    deps = [
        ":logical_session_id",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "logical_session_cache_noop",
    hdrs = [
        "logical_session_cache_noop.h",
    ],
    deps = [
        ":logical_session_cache",
    ],
)

idl_generator(
    name = "kill_sessions_gen",
    src = "kill_sessions.idl",
    deps = [
        ":logical_session_id_gen",
        "//src/mongo/crypto:sha256_block_gen",
        "//src/mongo/db:basic_types_gen",
    ],
)

mongo_cc_library(
    name = "kill_sessions",
    srcs = [
        "kill_sessions.cpp",
        "kill_sessions_common.cpp",
        "session_killer.cpp",
        ":kill_sessions_gen",
    ],
    hdrs = [
        "kill_sessions.h",
        "kill_sessions_common.h",
        "kill_sessions_util.h",
        "session_killer.h",
    ],
    deps = [
        ":logical_session_id_helpers",
        "//src/mongo/db:api_parameters",
        "//src/mongo/db:server_base",
        "//src/mongo/db/auth",
        "//src/mongo/db/auth:authprivilege",
        "//src/mongo/db/auth:user",
        "//src/mongo/rpc:client_metadata",
        "//src/mongo/util/concurrency:spin_lock",  # TODO(SERVER-93876): Remove.
    ],
)

idl_generator(
    name = "internal_transactions_reap_service_gen",
    src = "internal_transactions_reap_service.idl",
)

idl_generator(
    name = "session_txn_record_gen",
    src = "session_txn_record.idl",
    deps = [
        ":logical_session_id_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/repl:replication_types_gen",
    ],
)

mongo_cc_library(
    name = "logical_session_id",
    srcs = [
        "logical_session_id.cpp",
        ":logical_session_id_gen",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/crypto:sha256_block",
        "//src/mongo/crypto:sha_block",
        "//src/mongo/idl:idl_parser",
    ],
)

mongo_cc_library(
    name = "session_catalog",
    srcs = [
        "session_catalog.cpp",
    ],
    hdrs = [
        "session.h",
        "session_catalog.h",
    ],
    deps = [
        ":kill_sessions",
        ":logical_session_id",  # TODO(SERVER-93876): Remove.
        ":logical_session_id_helpers",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:internal_transactions_feature_flag",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:service_context",
        "//src/mongo/db/concurrency:lock_manager",
        "//src/mongo/util:fail_point",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util/concurrency:spin_lock",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "sessions_server_parameters_idl",
    srcs = ["//src/mongo/db/session:sessions_server_parameters_gen"],
    deps = ["//src/mongo/db:server_base"],
)

mongo_cc_library(
    name = "sessions_collection",
    srcs = [
        "sessions_collection.cpp",
    ],
    hdrs = [
        "sessions_collection.h",
    ],
    deps = [
        ":logical_session_id",  # TODO(SERVER-93876): Remove.
        ":logical_session_id_helpers",  # TODO(SERVER-93876): Remove.
        ":sessions_server_parameters_idl",
        "//src/mongo/client:clientdriver_minimal",
        "//src/mongo/db:coll_mod_command_idl",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:index_commands_idl",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:server_base",
    ],
)

mongo_cc_library(
    name = "logical_session_cache_impl",
    srcs = [
        "logical_session_cache_impl.cpp",
        "service_liaison.cpp",
        "service_liaison_impl.cpp",
        "service_liaison_router.cpp",
    ],
    hdrs = [
        "logical_session_cache_impl.h",
        "service_liaison.h",
        "service_liaison_impl.h",
        "service_liaison_router.h",
    ],
    deps = [
        ":kill_sessions",
        ":logical_session_cache",
        ":logical_session_id_helpers",
        ":sessions_collection",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:shard_role_api",
    ],
)

mongo_cc_library(
    name = "sessions_collection_rs",
    srcs = [
        "sessions_collection_rs.cpp",
    ],
    hdrs = [
        "sessions_collection_rs.h",
    ],
    deps = [
        ":sessions_collection",
        "//src/mongo:base",
        "//src/mongo/client:authentication",
        "//src/mongo/client:remote_command_targeter",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db/concurrency:lock_manager",
        "//src/mongo/db/repl:repl_coordinator_interface",
    ],
)

mongo_cc_library(
    name = "kill_sessions_remote",
    srcs = [
        "kill_sessions_remote.cpp",
    ],
    hdrs = [
        "kill_sessions_remote.h",
    ],
    deps = [
        ":kill_sessions",
        "//src/mongo/db:query_exec",
        "//src/mongo/executor:async_multicaster",
    ],
)

mongo_cc_library(
    name = "service_liaison_mongod",
    srcs = [
        "service_liaison_shard.cpp",
        "sessions_collection_standalone.cpp",
    ],
    hdrs = [
        "service_liaison_shard.h",
        "sessions_collection_standalone.h",
    ],
    deps = [
        ":logical_session_cache_impl",
        ":logical_session_id",
        ":sessions_collection",
        "//src/mongo:base",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:query_exec",
        "//src/mongo/db:service_context",
        "//src/mongo/db/query/client_cursor",
        "//src/mongo/s:grid",
        "//src/mongo/s/query/exec:cluster_cursor_manager",
        "//src/mongo/util:clock_sources",
        "//src/mongo/util:periodic_runner",
    ],
)

mongo_cc_library(
    name = "session_catalog_mongod",
    srcs = [
        "internal_transactions_reap_service.cpp",
        "session_catalog_mongod.cpp",
        ":internal_transactions_reap_service_gen",
        ":session_txn_record_gen",
    ],
    hdrs = [
        "internal_transactions_reap_service.h",
        "session_catalog_mongod.h",
        "session_catalog_mongod_transaction_interface.h",
        "//src/mongo/db/transaction:server_transactions_metrics.h",
        "//src/mongo/db/transaction:transaction_metrics_observer.h",
        "//src/mongo/db/transaction:transaction_participant.h",
        "//src/mongo/db/transaction:transactions_stats_gen",
    ],
    deps = [
        ":kill_sessions",
        ":logical_session_id",
        ":logical_session_id_helpers",
        ":session_catalog",
        "//src/mongo/db:coll_mod_command_idl",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db:index_commands_idl",
        "//src/mongo/db:internal_transactions_feature_flag",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db:shard_role",
        "//src/mongo/db/catalog:collection_options",
        "//src/mongo/db/commands:mongod_fcv",
        "//src/mongo/db/index_builds:index_builds_coordinator",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/repl:repl_server_parameters",
        "//src/mongo/db/repl:replica_set_aware_service",
        "//src/mongo/db/repl:storage_interface",
        "//src/mongo/util/concurrency:thread_pool",
    ],
)

mongo_cc_library(
    name = "kill_sessions_local",
    srcs = [
        "kill_sessions_local.cpp",
    ],
    hdrs = [
        "kill_sessions_local.h",
    ],
    deps = [
        ":kill_sessions",
        ":session_catalog",
        "//src/mongo/db:query_exec",
        "//src/mongo/db/query/client_cursor",
        "//src/mongo/db/transaction",
    ],
)

mongo_cc_library(
    name = "sessions_collection_mock",
    srcs = [
        "sessions_collection_mock.cpp",
    ],
    hdrs = [
        "sessions_collection_mock.h",
    ],
    deps = [
        ":logical_session_id",
        ":sessions_collection",
        "//src/mongo:base",
    ],
)

# TODO(SERVER-96853): Remove cycle created by moving //src/mongo/db/session:logical_session_id.h to //src/mongo/db/session:logical_session_id
filegroup(
    name = "logical_session_id_hdrs",
    srcs = [":logical_session_id.h"],
)

# TODO(SERVER-96853): Remove cycle created by moving //src/mongo/db/session:logical_session_id_helpers.h to //src/mongo/db/session:logical_session_id_helpers
filegroup(
    name = "logical_session_id_helpers_hdrs",
    srcs = [":logical_session_id_helpers.h"],
)
